package com.zr.web;

import com.alibaba.fastjson.JSON;
import com.zr.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
@WebServlet("/delete")
public class DeleteById extends HttpServlet {
    private BrandService service = new BrandService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 接收数据json
        BufferedReader br = req.getReader();
        String params = br.readLine();
        //System.out.println(params);
        //转为int
        int id = JSON.parseObject(params,int.class);
        //System.out.println(id);

        //2.调用service删除
        service.delete(id);

        //3.成功响应
        resp.getWriter().write("sucess");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
